package com.example.AIstudy.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.example.AIstudy.domain.Question;
import com.example.AIstudy.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface QuestionDao extends BaseMapper<Question> {

    //根据学生id获取学生所有问题的水平
    @Select("select queslevel from question where stuID = #{stuID}")
    public List<Integer> getLevelByStuID(int stuID);

    //新增一个问题信息，并且实现id回填
    @Insert("INSERT INTO question(question,queslevel,questime,stuID,quesLevelStr) " +
            "VALUES (#{question},#{queslevel},#{questime},#{stuID},#{quesLevelStr})")
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id",
            keyColumn = "id", resultType = Integer.class, before = false)
    void insertQuestion(Question question);

    //分页获取问题信息
    @Select("SELECT * FROM question ${ew.customSqlSegment}")
    public IPage<Question> findQuestion(IPage<Question> page,
                                 @Param(Constants.WRAPPER) QueryWrapper<Question> wrapper);

}
